package com.ruoyi.fetv.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fetv.domain.FetvColumn;
import com.ruoyi.fetv.service.IFetvColumnService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 栏目Controller
 *
 * @author lwj
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/fetv/column")
@CrossOrigin
public class FetvColumnController extends BaseController
{
    @Autowired
    private IFetvColumnService fetvColumnService;

    /**
     * 查询栏目列表
     */
//    @PreAuthorize("@ss.hasPermi('fetv:column:list')")
    @Anonymous
    @GetMapping("/list")
    public AjaxResult list(FetvColumn fetvColumn)
    {
        List<FetvColumn> list = fetvColumnService.selectFetvColumnList(fetvColumn);
        return success(list);
    }

    /**
     * 导出栏目列表
     */
    @PreAuthorize("@ss.hasPermi('fetv:column:export')")
    @Log(title = "栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FetvColumn fetvColumn)
    {
        List<FetvColumn> list = fetvColumnService.selectFetvColumnList(fetvColumn);
        ExcelUtil<FetvColumn> util = new ExcelUtil<FetvColumn>(FetvColumn.class);
        util.exportExcel(response, list, "栏目数据");
    }

    /**
     * 获取栏目详细信息
     */
    @Anonymous
//    @PreAuthorize("@ss.hasPermi('fetv:column:query')")
    @GetMapping(value = "/{columnId}")
    public AjaxResult getInfo(@PathVariable("columnId") Long columnId)
    {
        return success(fetvColumnService.selectFetvColumnByColumnId(columnId));
    }

    /**
     * 新增栏目
     */
//    @PreAuthorize("@ss.hasPermi('fetv:column:add')")
    @Anonymous
    @Log(title = "栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FetvColumn fetvColumn)
    {
        return toAjax(fetvColumnService.insertFetvColumn(fetvColumn));
    }

    /**
     * 修改栏目
     */
//    @PreAuthorize("@ss.hasPermi('fetv:column:edit')")
    @Anonymous
    @Log(title = "栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FetvColumn fetvColumn)
    {
        return toAjax(fetvColumnService.updateFetvColumn(fetvColumn));
    }

    /**
     * 删除栏目
     */
//    @PreAuthorize("@ss.hasPermi('fetv:column:remove')")
    @Anonymous
    @Log(title = "栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{columnIds}")
    public AjaxResult remove(@PathVariable Long[] columnIds)
    {
        return toAjax(fetvColumnService.deleteFetvColumnByColumnIds(columnIds));
    }

    /**
     * 修改状态码
     * id 栏目id
     * status 状态码
     */
    @GetMapping("status")
    @Anonymous
    public AjaxResult editStatus(@RequestParam Long columnid,Integer status)
    {
        FetvColumn fetvColumn = fetvColumnService.selectFetvColumnByColumnId(columnid);
        fetvColumn.setStatus(status);
        return toAjax(fetvColumnService.updateFetvColumn(fetvColumn));
    }

}
